// index page
// ============

define(['zepto', 'utils', 'JST', 'sui'], function($, utils, JST) {
  return {
    init: function(data) {
      this.order = data.order;
      this.bindLocationEditPageEvent();
      console.log(this.order);
    },
    
    bindLocationEditPageEvent: function($page) {
      var that = this,
        $location = $('textarea[name="address"]');
    
        $(document).on('click', '#submit', function(e) {
    
          e.preventDefault()
    
          var location = $location.val().trim()
          if(!location) {
            $.toast('收货地址不能为空')
          } else {
            $.showIndicator()
            $.post(window.__CTX__.root + "/orders/shipping-address?order=" + that.order, {
              'address': location,
              '_method': 'PATCH'
            }).done(function(response) {
              $.hideIndicator()
              utils.processResult(response, function(result) {
                $.toast(result.message || '修改成功', 1000)
                setTimeout(function(e){
                  window.location.href = __CTX__.root + '/pay?order=' + that.order;
                }, 1000)
              }, function(result) {
                $.toast(result.message || '修改失败')
              })
            })
          }
          
        })
    }
    
  }
})